/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.resourceManager;

import java.util.List;

import org.nudt.jCloud.infrastructure.Cluster;
import org.nudt.jCloud.infrastructure.Slot;
import org.nudt.jCloud.infrastructure.SlotType;
import org.nudt.jCloud.simulation.CloudSchedSIM;
import org.nudt.jCloud.simulation.ScaleData;
import org.nudt.jCloud.simulation.UserBroker;

public class GeneralReservationRM extends ReservationRM{

	public GeneralReservationRM(String name, Cluster cluster) {
		super(name, cluster);
	}

	@Override
	public void scaleResource(List<ScaleData> scaleDataList) {
		for(ScaleData scaleData : scaleDataList){
			UserBroker userBroker = (UserBroker) CloudSchedSIM.getEntityById(scaleData.getUserBrokerId());
			for(SlotType slotType : scaleData.getToReleaseSlot().keySet()){
				List<Slot> slotList = scaleData.getToReleaseSlot().get(slotType);
				releaseSlot(slotList);
			}
			for(SlotType slotType : scaleData.getToLeaseSlot().keySet()){
				List<Slot> slotList = provideSlots(slotType, scaleData.getToLeaseSlot().get(slotType));
				if(slotList.size()>0){
					userBroker.getFrwk().leaseSlot(slotType, slotList);
				}
			}
		}
	}

}
